package ui;

import config.ConfigFactory;
import config.GameConfig;

import javax.swing.*;
import java.awt.*;

public class JFrameGame extends JFrame {


    public JFrameGame(JPanelGame panelGame) {
        GameConfig cfg = ConfigFactory.getGameConfig();

        //设计标题
        this.setTitle(cfg.getTitle());
        //设置默认关闭
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置大小
        this.setSize(cfg.getWidth(),cfg.getHeight());
        //设置用户不能移动
        this.setResizable(false);
        //设置居中
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screen = toolkit.getScreenSize();
        int x = (screen.width - this.getWidth())>>1;
        int y = ((screen.height - this.getHeight())>>1) - cfg.getWindowUp();
        this.setLocation(x,y);
        //设置默认Panel
        this.setContentPane(panelGame);
        //默认窗口显示
        this.setVisible(true);
    }
}
